/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.put.netbeans.dcs_modeler.dataObjects;

import com.thoughtworks.xstream.XStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Vector;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.nodes.CookieSet;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.put.netbeans.dcs_modeler.actions.DCSComputingObjectOpenSuport;
import org.put.netbeans.dcs_modeler.dataObjects.modelerEntities.dcsComputingObject.DCSComputingObject;

public class DCSComputingObjectDefinitionDataObject extends MultiDataObject
{
    private DCSComputingObject  computingObject;
            
    public DCSComputingObjectDefinitionDataObject( FileObject pf, DCSComputingObjectDefinitionDataLoader loader ) throws DataObjectExistsException, IOException
    {
        super( pf, loader );
        CookieSet cookies = getCookieSet();
       // cookies.add( ( Node.Cookie )DataEditorSupport.create( this, getPrimaryEntry(), cookies ) );
        cookies.add( ( Node.Cookie )new DCSComputingObjectOpenSuport( getPrimaryEntry() ) );
        computingObject = loadComputingObject( pf );
    }

    @Override
    protected Node createNodeDelegate()
    {
        return new DCSComputingObjectDefinitionDataNode( this, getLookup() );
    }

    @Override
    public Lookup getLookup()
    {
        return getCookieSet().getLookup();
    }
    
    private DCSComputingObject loadComputingObject( FileObject openedFile ) throws FileNotFoundException
    {
            XStream xStream = new XStream();
            return ( DCSComputingObject )xStream.fromXML( openedFile.getInputStream() );
    }

    public DCSComputingObject getComputingObject()
    {
        return computingObject;
    }

    public void setComputingObject( DCSComputingObject computingObject )
    {
        this.computingObject = computingObject;
    }
    
    public void addPortIn( HashMap< String, Object > portIn )
    {
        computingObject.addPortIn( portIn );
    }
    
    public void addPortOut( HashMap< String, Object > portOut )
    {
        computingObject.addPortOut( portOut );
    }
    
    public Vector<HashMap<String, Object>> getPortInVector()
    {
        return computingObject.getPortIn();
    }
    
    public Vector<HashMap<String, Object>> getPortOutVector()
    {
        return computingObject.getPortOut();
    }
    
    public void setPortInVector( Vector<HashMap<String, Object>> vect )
    {
        computingObject.setPortIn( vect );
    }
    
    public void setPortOutVector( Vector<HashMap<String, Object>> vect )
    {
        computingObject.setPortOut( vect );
    }
}
